(function() {

this.pasta = this.pasta || {};
this.pasta.webgui = this.pasta.webgui || {};

this.pasta.webgui.Label = pasta.webgui.Control.extend(
{
	init : function() 
	{
		this._super();
		
		this.caption = "";
		
		this.font = new pasta.util.Font();
		this.font.getOnChange().setHandler(this, this.doFontChanged);
		
		this.canvas.innerHTML = this.font.wrapHTML(this.caption);
		this.canvas.textAlign = "left";
		this.canvas.style.overflow = "hidden";
		
		this.tmpCanvas = null;
		this.wordWrap = true;
		
		this.setHeight(20);
	},
	
	getTextWidth : function()
	{
		if (pasta.webgui.tmpCanvas == null)
		{
			pasta.webgui.tmpCanvas = document.createElement("div");
			
			pasta.webgui.tmpCanvas.id = this.cid + "_tmp";
			pasta.webgui.tmpCanvas.style.position = "absolute";
			pasta.webgui.tmpCanvas.style.left = "-2000px";
			pasta.webgui.tmpCanvas.style.top = "-2000px";
			pasta.webgui.tmpCanvas.style.width = "auto";
			pasta.webgui.tmpCanvas.style.height = "auto";
			
			document.getElementById("stage").appendChild(pasta.webgui.tmpCanvas);
		}
		
		pasta.webgui.tmpCanvas.innerHTML = this.caption;
		this.font.applyFont(pasta.webgui.tmpCanvas);
		
		return pasta.webgui.tmpCanvas.clientWidth + 1;
	},
	
	getTextHeight : function()
	{
		if (pasta.webgui.tmpCanvas == null)
		{
			pasta.webgui.tmpCanvas = document.createElement("div");
			
			pasta.webgui.tmpCanvas.id = this.cid + "_tmp";
			pasta.webgui.tmpCanvas.style.position = "absolute";
			pasta.webgui.tmpCanvas.style.left = "-2000px";
			pasta.webgui.tmpCanvas.style.top = "-2000px";
			pasta.webgui.tmpCanvas.style.width = "auto";
			pasta.webgui.tmpCanvas.style.height = "auto";
			
			document.getElementById("stage").appendChild(pasta.webgui.tmpCanvas);
		}
		
		pasta.webgui.tmpCanvas.innerHTML = this.caption;
		this.font.applyFont(pasta.webgui.tmpCanvas);
		
		return pasta.webgui.tmpCanvas.clientHeight + 1;
	},
	
	//----------------------- Event -----------------------
	
	doFontChanged : function()
	{
		this.font.applyFont(this.canvas);
	},
	
	//----------------------- Setter & Getter ------------------
	
	isWordWrap : function()
	{
		return this.wordWrap;
	},
	
	setWordWrap : function(data)
	{
		this.wordWrap = data;
		
		if (this.wordWrap)
		{
			this.canvas.style.textOverflow = "ellipsis";
			this.canvas.style.whiteSpace = "";
		}
		else
		{
			this.canvas.style.textOverflow = "ellipsis";
			this.canvas.style.whiteSpace = "nowrap";
		}
	},
	
	getAlign : function()
	{
		return this.canvas.textAlign;
	},
	
	setAlign : function(align)
	{
		this.canvas.style.textAlign = align;
	},
	
	getCaption : function()
	{
		return this.caption;
	},
	
	setCaption : function(data)
	{
		if ((data == undefined) || (data == null))
			data = "";
		
		this.caption = data;
		this.canvas.innerHTML = data;
		
		if (this._onChange != null)
			this._onChange.callHandler(this, data);
	},
	
	setShadow : function(data)
	{
		this.shadow = data;
		this.canvas.style.textShadow = data;
	},
	
	//-----------------Event Object --------------
	
	getOnChange : function()
	{
		if (this._onChange == null)
			this._onChange = new pasta.util.EventObj();
		
		return this._onChange;
	},
});

})();